package com.utonw.carloan.global;

import android.content.Intent;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;

import com.utonw.carloan.R;
import com.utonw.carloan.activity.applyloan.LoanProductActivity;
import com.utonw.carloan.activity.applyloan.LoanEntryActivity;
import com.utonw.carloan.activity.base.BaseActivity;
import com.utonw.carloan.activity.mybills.ShowMyBillsActivity;
import com.utonw.carloan.adpter.main.MainGuideAdapter;
import com.utonw.carloan.bean.main.MainGuideBean;
import com.utonw.carloan.utils.ChooseBarUtils;
import com.utonw.carloan.utils.DividerGridItemDecorationUtils;
import com.utonw.carloan.utils.UIUtils;

import java.util.ArrayList;

/**
 * Created by SEELE on 2017/3/22.
 */

/**
 * 存放首页一些共通显示方法
 */
public class InitData {

    private BaseActivity mActivity;

    public InitData(BaseActivity activity) {
        mActivity = activity;
    }

    //初始化复杂ChooseBar
    public void initComplexChooseBar() {
        //初始化ComplexChooseBar
        ChooseBarUtils titleUtils = new ChooseBarUtils(mActivity) {
            @Override
            protected void setChooseBarClickListener(int view) {
                switch (view) {
                    case R.id.cheshangdai:
                        //跳转到车商贷页面
                        BaseActivity.startAnActivity(new Intent(mActivity, LoanEntryActivity.class));
                        break;
                    case R.id.chedidai:
                        UIUtils.showShortToast("车抵贷");
                        break;
                    case R.id.chefenqi:
                        UIUtils.showShortToast("车分期");
                        break;
                }
            }

            @Override
            protected void setChooseBarClickListener(int view, TextView toShow) {

            }

            @Override
            protected void getCheckedViewListener(int includeId, int sTitle, View toCheck) {

            }

            @Override
            public void onToggleButtonListener(int buttonView, boolean isChecked) {

            }

            @Override
            public void getEditTextWithTipsListener(int includeId, EditText tempEt1) {

            }

            @Override
            public void onRadioButtonListener(RadioButton rMale, RadioButton rFemale) {

            }

            @Override
            public void onImageChooseBarListener(int view, ImageView mIndicator, TextView mInstruction, int sTitle) {

            }

            @Override
            public void getChangeWordsEditTextListener(int includeId, EditText tempEt1, int sTitle) {

            }

            @Override
            public void setVerificationListener() {

            }
        };

        titleUtils.initComplexChooseBar(R.id.cheshangdai, R.string.function_car_loan, "6666", "1.29%");
        titleUtils.initComplexChooseBar(R.id.chefenqi, R.string.function_car_fenqi, "8888", "1.39%");
        titleUtils.initComplexChooseBar(R.id.chedidai, R.string.function_car_didai, "9999", "1.49%");
    }


    //初始化首页顶部导航栏
    public void initGuideRecyclerView(RecyclerView guideView,int themeType) {
        //权限Module 集合
        ArrayList<MainGuideBean> guideData = new ArrayList<>();
        /**
         * 参数1：显示的图标资源id
         * 参数2：显示的功能文字
         * 参数3：是否开启小红点
         */

        switch (themeType){
            case Constants.THEME_BROWN:
                //申请贷款
                guideData.add(new MainGuideBean(R.mipmap.skin_main_xjdd_icon_brown, R.string.main_guide_apply_money, false));
                //客户管理
                guideData.add(new MainGuideBean(R.mipmap.skin_main_kh_icon_brown, R.string.main_guide_customer_manager, false));
                //自助小工具
                guideData.add(new MainGuideBean(R.mipmap.skin_main_cxye_icon_brown, R.string.main_guide_tools, false));
                //我的订单
                guideData.add(new MainGuideBean(R.mipmap.skin_main_jdcx_icon_brown, R.string.main_guide_my_bills, true));
                //逾期催单
                guideData.add(new MainGuideBean(R.mipmap.skin_main_yq_icon_brown, R.string.main_guide_out_of_data, true));
                //我的提成
                guideData.add(new MainGuideBean(R.mipmap.skin_main_yjtc_icon_brown, R.string.main_guide_my_money, false));
                //待办任务
                guideData.add(new MainGuideBean(R.mipmap.skin_main_wddb_icon_brown, R.string.main_guide_need_to_do, true));
                //已办任务
                guideData.add(new MainGuideBean(R.mipmap.skin_main_yb_icon_brown, R.string.main_guide_already_did, false));
            break;

            case Constants.THEME_ORANGE:
                //申请贷款
                guideData.add(new MainGuideBean(R.mipmap.skin_main_xjdd_icon_orange, R.string.main_guide_apply_money, false));
                //客户管理
                guideData.add(new MainGuideBean(R.mipmap.skin_main_kh_icon_orange, R.string.main_guide_customer_manager, false));
                //自助小工具
                guideData.add(new MainGuideBean(R.mipmap.skin_main_cxye_icon_orange, R.string.main_guide_tools, false));
                //我的订单
                guideData.add(new MainGuideBean(R.mipmap.skin_main_jdcx_icon_orange, R.string.main_guide_my_bills, true));
                //逾期催单
                guideData.add(new MainGuideBean(R.mipmap.skin_main_yq_icon_orange, R.string.main_guide_out_of_data, true));
                //我的提成
                guideData.add(new MainGuideBean(R.mipmap.skin_main_yjtc_icon_orange, R.string.main_guide_my_money, false));
                //待办任务
                guideData.add(new MainGuideBean(R.mipmap.skin_main_wddb_icon_orange, R.string.main_guide_need_to_do, true));
                //已办任务
                guideData.add(new MainGuideBean(R.mipmap.skin_main_yb_icon_orange, R.string.main_guide_already_did, false));
                break;
        }



        MainGuideAdapter mainGuideAdapter = new MainGuideAdapter(mActivity);
        // TODO: 2017/3/21 根据传入的权限id不同，生成不同的首页功能区，目前暂时最大：8个功能,最小0个功能

        mainGuideAdapter.setData(guideData);
        //回调RecycleView点击事件
        mainGuideAdapter.setOnItemClickListener(new MainGuideAdapter.MyClickListener() {
            @Override
            public void onItemClickListener(int title) {
                switch (title) {
                    //申请贷款
                    case R.string.main_guide_apply_money:
                        BaseActivity.startAnActivity(new Intent(mActivity, LoanProductActivity.class));
                        break;
                    //客户管理
                    case R.string.main_guide_customer_manager:

                        break;
                    //自助小工具
                    case R.string.main_guide_tools:

                        break;
                    //我的订单
                    case R.string.main_guide_my_bills:
                        BaseActivity.startAnActivity(new Intent(mActivity, ShowMyBillsActivity.class));
                        break;
                    //逾期催单
                    case R.string.main_guide_out_of_data:

                        break;
                    //我的提成
                    case R.string.main_guide_my_money:

                        break;

                    //待办任务
                    case R.string.main_guide_need_to_do:

                        break;
                    //已办任务
                    case R.string.main_guide_already_did:

                        break;
                }

            }
        });

        guideView.setAdapter(mainGuideAdapter);
        guideView.setLayoutManager(new GridLayoutManager(mActivity, 3));
        //添加分割线
        DividerGridItemDecorationUtils itemDecoration = new DividerGridItemDecorationUtils(mActivity);
        guideView.addItemDecoration(itemDecoration);

    }
}
